#pragma once
#include "../common/atomic.h"

struct IUnknown
{
	virtual long	AddRef() = 0;
	virtual long	Release() = 0;
};

template <class TClass, class TBase, bool AutoDelete = true>
class TComBase : virtual public TBase
{
public:
	TComBase()
	{
		m_nRef = 1;
	}

	~TComBase()
	{
	}

private:
	long		m_nRef;

public:
	virtual long AddRef()
	{
		return InterlockedIncrement(&m_nRef);
	}

	virtual long Release()
	{
		long	ref		= InterlockedDecrement(&m_nRef);

		if(AutoDelete && ref <= 0)
		{
			delete (TClass *)this;
		}

		return ref;
	}
};

